package com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.web;

import com.alibaba.fastjson.JSONObject;
import com.iwhalecloud.citybrain.flow.platform.manager.application.service.CommandHandleManager;
import com.iwhalecloud.citybrain.flow.platform.manager.common.ResponseResult;
import com.iwhalecloud.citybrain.flow.platform.manager.common.client.HttpCommandResultDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lilh
 * @date 2019-02-18 21:32
 */
@RestController
@RequestMapping("/restful")
public class FlowClientController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CommandHandleManager commandHandleManager;


    /**
     * 客户端调用
     *
     * @param params 参数
     * @return 结果
     */
    @PostMapping("/call")
    public ResponseResult call(@RequestBody String params) {
        logger.info("请求消息为{}", params);
        HttpCommandResultDto resultDto = commandHandleManager.handle(params);
        logger.info("返回参数为：{}", JSONObject.toJSONString(resultDto.toMap()));
        return ResponseResult.success(resultDto);
    }

}
